﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


public class Tree
{
	private List<Tree> childs;
	public int? Value;
	public List<Tree> Childs
	{
		get
		{
			if (childs == null)
			{
				childs = new List<Tree>();
			}
			return childs;
		}
	}
}

public class Program
{
    static void Main(string[] args)
    {
		string input = Console.ReadLine();
		Tree three = ReadTree(input);

        BFS(three);
    }

	static Tree ReadTree(string input)
	{
		string substring = input.Substring(1, input.Length - 2);
		int index = 0;
		StringBuilder sb = new StringBuilder();
		while (index < substring.Length && ((index == 0 && substring[index] == '-') || char.IsDigit(substring[index])))
		{
			sb.Append(substring[index]);
			index++;
		}

		Tree tree;

		tree = new Tree() { Value = int.Parse(sb.ToString()) };


		if (substring.Length >= 2 && substring[0] == '-' && char.IsDigit(substring[1]))
		{
			substring = substring.TrimStart("-0123456789".ToCharArray());
		}

		substring = substring.TrimStart("0123456789".ToCharArray());

		if (substring.Length >= 2 && (substring[0] == '>' || substring[1] == '>'))
		{
			substring = substring.TrimStart("->".ToCharArray());
		}


		if (substring.Length > 0)
		{
			List<string> branches = SplitBranches(substring);

			int leaf;
			foreach (var branch in branches)
			{
				if (branch[0] == 'x')
				{
					tree.Childs.Add(new Tree() { Value = null });
				}
				else
				{
					if (int.TryParse(branch, out leaf))
					{
						tree.Childs.Add(new Tree() { Value = leaf });
					}
					else
					{
						tree.Childs.Add(ReadTree(branch));
					}
				}
			}
		}
		return tree;
	}

	static List<string> SplitBranches(string input)
	{
		List<string> split = new List<string>();
		int count = 0;
		StringBuilder sb = new StringBuilder();
		foreach (var ch in input)
		{
			if (ch == ',' && count == 0)
			{
				split.Add(sb.ToString());
				sb.Clear();
				continue;
			}
			sb.Append(ch);
			if (ch == '(')
			{
				count++;
			}
			if (ch == ')')
			{
				count--;
			}
		}
		split.Add(sb.ToString());
		return split;
	}

    private static void BFS(Tree node)
    {
		Queue<Tree> queue = new Queue<Tree>();
        queue.Enqueue(node);

        while (queue.Count > 0)
        {
            var nextNode = queue.Dequeue();
            bool canPrint = true;

            foreach (var child in nextNode.Childs)
            {
                if (child.Childs.Count > 0)
                {
                    canPrint = false;
                }
                queue.Enqueue(child);
            }

            if (canPrint && nextNode.Childs.Count > 0)
            {
                Console.WriteLine(nextNode.Value);
            }
        }
    }
}

